<?php $this->_extends('_layouts/default_layout'); ?>
 
<?php $this->_block('contents'); ?>
 
<span ><a href="<?php echo url('notification/index'); ?>">查看历史通知</a></span>
<br/>
<br/>
<form action="<?php echo url('notification/write'); ?>" method="post" name="form" 
        onsubmit="
		if (this.notification_name.value == '') { 
		alert('请输入通知标题'); 
		return false; }
		else { 
			if (this.notification_desc.value == '') 
			{ 
			alert('请输入通知内容'); 
			return false; 
			}
			return true; 
		}" enctype="multipart/form-data">
	<table cellpadding="0" cellspacing="0" width="100%">
		<tr>
		<td><span class="defaultbold">通知标题</span><br /></td>
		<td><input class="input" type="text" value="" name="notification_name" id="name" size="58" /></td>
	</tr>

	<tr>
		<td><span class="defaultbold">发给部门</span><br /></td>
		<td>
		<select name="department_id" id="department_id">
			<option value="-1" id="-1">
				所有部门
			</option>
			<?php foreach ($deps as $depd): ?>
				<option value="<?php echo $depd->department_id ?>" onselect="OnShowDepartMent(<?php echo $depd->department_id ?>+1024)" id="<?php echo $depd->department_id ?>">
					<?php echo $depd->department_name; ?>
				</option>
			<?php endforeach; ?>			
		</select>
        <span><a onclick="displaydep()" id="disp_or_hide" style="cursor:pointer;">显示部门成员</a></span>
		</td>
	</tr>
	<tr>
        <td></td>
        <td>
                <div id="user_select"  style="display:none">
                        
                </div>
        </td>
	</tr>
    <tr>
                <td><span class="defaultbold ">在通知末尾自动追加时间</span><br /></td>
		<td><input class="input" type="checkbox" name="append_time" checked="checked"/></td>
    </tr> 

<script language="javascript">  
function countChar(textareaName,spanName){
    document.getElementById(spanName).innerHTML=500-document.getElementById(textareaName).value.length;
    if(document.getElementById(textareaName).value.length>=500){
        window.alert("超过最大字数！")
        return false;
    }
}
</script>  

    <tr>
                <td> </td>
                <td>可以输入<span id="counter">500</span>字<br></td>
    </tr>
    <tr>
		<td><span class="defaultbold ">通知内容</span><br /></td>
		<td><textarea name="notification_desc" id="notification_desc" rows="10" cols="45" onkeydown='countChar("notification_desc","counter");' onkeyup="countChar('notification_desc','counter')"; ></textarea></td>
	</tr>

	<tr>
		<td class="tbutton" colspan="2"><input type="submit" value="确认发送" class="btn" name="submit"> </td>
	</tr>
		</table>
</form>


<script language="javascript">
    var xmlHttp = false;
    if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
    }
    document.getElementById("department_id").onchange=_f;

    function _f()
    {   
      var dep_id = document.getElementById("department_id").value;

      var url = "<?php echo url('Notification/getuserfromdepid'); ?>";
      var poststr="&dep_id=" + escape(dep_id);

      // Open a connection to the server
      xmlHttp.open("POST", url, true);
      xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

      // Setup a function for the server to run when it's done
      xmlHttp.onreadystatechange = updatePage;
      
      // Send the request
      xmlHttp.send(poststr);
    }

    function displaydep()
    {   
      var dep_id = -1;
      var objSrc = document.getElementById ("disp_or_hide");
      var objDiv = document.getElementById ("user_select");
      if (objDiv.style.display== "none")
      {
          objDiv.style.display = "";
          objSrc.innerHTML = "隐藏部门成员";
      }
      else
      {
          objDiv.style.display = "none";
          objSrc.innerHTML = "显示部门成员";
      }
      return _f();
    }
    function updatePage() {
      if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
          var response_str = xmlHttp.responseText;
          //从服务端返回json的数据,组织为html
          //'user_id':10,
          //'user_name':李宜章,
          //alert(response_str);
          if(response_str.length == 0)
          {
              alert("该部门目前没有职员");
              document.getElementById("department_id").value = -1;
              return;
          }
          $('#user_select').html(response_str);
      }
    }
</script>
<?php $this->_endblock(); ?>
